package buttons
{
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.text.TextField;

	public class TextButton extends SimpleButton
	{
		
		private var _text:String;
		private var _width:int;
		private var _height:int;
		
		public function TextButton( text:String, width:int, height:int ) {
			
			setText( text );
			setWidth( width );
			setHeight( height );
			setStates();
						
		}
		
		private function setStates():void {
			
			upState = createUpState();
			overState = upState;
			downState = upState;
			hitTestState = overState;
			
		}
		
		private function createUpState():Sprite {
			
			var sprite:Sprite = new Sprite();
			sprite.graphics.beginFill( 0x666666, 0.6 );
			sprite.graphics.drawRoundRect( 0, 0, _width, _height, 3, 3 );
			sprite.graphics.endFill();
				
			var textField:TextField = new TextField();
			textField.text = _text;
			textField.textColor = 0x000000;
			textField.x = ( _width - textField.textWidth ) / 2;
			textField.y = ( _height - textField.textHeight ) / 2;
			
			sprite.addChild( textField );
			
			return sprite;			
			
		}
		
		private function setText( text:String ):void {
			
			_text = text;
			
		}
		
		private function setWidth( width:int ):void {
			
			_width = width;
			
		}
		
		private function setHeight( height:int ):void {
			
			_height = height;
			
		}
		
	}
}
